
#include "OmPublic.h"
#include "OmException.h"

namespace OmPublic 
{
	Exception::Exception(int num, const String& desc, const String& src) :
		mLine( 0 ),
		mNumber( num ),
		mDescription( desc ),
		mSource( src )
	{
	// Log this error - not any more, allow catchers to do it
	//LogManager::getSingleton().logMessage(this->getFullDescription());
	}

	Exception::Exception(int num, const String& desc, const String& src, 
					 const TCHAR* typ, const char* fil, long lin) :
		mLine( lin ),
		mNumber( num ),
		mTypename(typ),
		mDescription( desc ),
		mSource( src ),
		mFile( fil )
	{
		// Log this error, mask it from debug though since it may be caught and ignored
		if(LogManager::getSingletonPtr())
		{
			LogManager::getSingleton().logMessage(
				this->getFullDescription(), 
				Log::LL_CRITICAL, true);
		}

	}

	Exception::Exception(const Exception& rhs)
		: mLine( rhs.mLine ), 
		mNumber( rhs.mNumber ), 
		mTypename( rhs.mTypename ), 
		mDescription( rhs.mDescription ), 
		mSource( rhs.mSource ), 
		mFile( rhs.mFile )
	{
	}

	void Exception::operator = ( const Exception& rhs )
	{
		mDescription = rhs.mDescription;
		mNumber = rhs.mNumber;
		mSource = rhs.mSource;
		mFile = rhs.mFile;
		mLine = rhs.mLine;
		mTypename = rhs.mTypename;
	}

	const String& Exception::getFullDescription(void) const
	{
		if (mFullDesc.empty())
		{
			mFullDesc.format(_T("OM EXCEPTION(%d:%s:) %s in %s"), 
				mNumber, 
				mTypename.c_str(), 
				mDescription.c_str(), 
				mSource.c_str());

			if (mLine > 0)
			{
				String tmp;
				tmp.format(_T(" at %s (line %d)"), mFile.c_str(), mLine);
				mFullDesc += tmp;
			}
		}

		return mFullDesc;
	}

	int Exception::getNumber(void) const throw()
	{
		return mNumber;
	}

}

